package com.example.demo.interceptor;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

public class CountInterceptor implements ProducerInterceptor<String,String> {

    int success;

    int error;

    @Override
    public ProducerRecord<String, String> onSend(ProducerRecord<String, String> record) {
        return null;
    }

    @Override
    public void onAcknowledgement(RecordMetadata metadata, Exception exception) {
        if(metadata != null){
            success++;
        }
        if(exception != null){
            error++;
        }
    }

    @Override
    public void close() {
        System.out.println("success="+success);
        System.out.println("error="+error);
    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
